package group.sicher.log.recorder;

import group.sicher.log.model.MethodRecord;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;

/**
 * @author Donald
 * @description
 * @date 2019-08-05
 **/
@Slf4j
public class MethodLogRecorder implements MethodRecorder {

    @Override
    public void record(JoinPoint joinPoint, Object result, long cost) {
        MethodRecord record = MethodRecord.of(joinPoint, result, cost);

        log.info("requestId: {}, class: {}, method: {}, params: {}, cost: {} ms",
                record.getRequestId(), record.getClassName(), record.getMethodName(), record.getParams(), record.getCost());
    }

    @Override
    public void record(JoinPoint joinPoint, Throwable e) {
        MethodRecord record = MethodRecord.of(joinPoint, e);

        log.error("requestId: {}, class: {}, method: {}, params: {}, exception: {}",
                record.getRequestId(), record.getClassName(), record.getMethodName(), record.getParams(), record.getExceptionMsg());
    }
}
